﻿using Microsoft.UI.Xaml;

namespace DNFImagePacks2Manager.Helpers
{
    // 主题工具
    public sealed class ThemeTool
    {
        // 初始化主题
        public static void InitAppTheme(Window? window)
        {
            string theme = LocalStorageHelper.GetAppTheme();
            ApplyAppTheme(theme, window);
        }

        // 应用主题
        public static void ApplyAppTheme(string theme)
        {
            Window? window = App.GetMainWindow();
            ApplyAppTheme(theme, window);
        }

        // 应用主题
        public static void ApplyAppTheme(string theme, Window? window)
        {
            if (window != null && window.Content is FrameworkElement rootElement)
            {
                switch (theme)
                {
                    case "浅色":
                        rootElement.RequestedTheme = ElementTheme.Light;
                        break;
                    case "深色":
                        rootElement.RequestedTheme = ElementTheme.Dark;
                        break;
                    case "使用系统设置":
                    default:
                        rootElement.RequestedTheme = ElementTheme.Default;
                        break;
                }
            }
        }
    }
}